package io.gitee.wminyu.day03.Sort;

import java.util.Arrays;
import java.util.Scanner;

public class Selection_sort {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int m = input.nextInt();
        int arrays[] = new int[m];
        for (int i=0;i<m;i++){
            arrays[i] = input.nextInt();
        }
        System.out.println("原数组为："+ Arrays.toString(arrays));
        Selection(arrays);
    }
    public static void Selection(int[] a){
        int i,j,temp,min,pos,flag;
        for (i=1;i<a.length;i++){
            min = a[i-1];
            pos = i-1;
            flag = 1;
            for (j=i;j<a.length;j++){
                if (min>a[j]){
                    min = a[j];
                    pos = j;
                    flag = 0;
                }
            }
            if (flag==0){
                temp = a[i-1];
                a[i-1] = a[pos];
                a[pos] = temp;
            }
            System.out.print("第"+i+"趟排序为：");
            Display(a);
            System.out.println();
        }
        System.out.println("最终排序为："+Arrays.toString(a));
    }
    public static void Display(int[] a){
        for (int i=0;i<a.length;i++){

            System.out.print(a[i]+" ");
        }
    }
}
